/*
 * Interfaz grafica que comunica al usuario con sus datos como jugador
 */
package interfazST;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.xml.parsers.ParserConfigurationException;
import jugador.Jugador;
import org.xml.sax.SAXException;
import servclien.*;

public class STInterface extends javax.swing.JFrame {

    private static Jugador _jugador; //Objeto que almacena los datos y entidades del usuario
    private boolean _insertarChoiceRaza;
    private String  _usuario;

    /**
     * Constructor, inicializa los componentes de la GUI, establece en false
     * la variable _insertarChoiceRaza que verifica si la raza ha sido inicializada e
     * inicializa el objeto jugador sin nombre ni raza.
     * @throws ParserConfigurationException
     * @throws SAXException
     * @throws IOException 
     * 
     */
    public STInterface() throws ParserConfigurationException, SAXException, IOException {
        initComponents();
        _insertarChoiceRaza = false;
        menuPrincipal();
        _jugador = new Jugador ();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelJuego = new javax.swing.JPanel();
        scrollPanelJuego = new javax.swing.JScrollPane();
        LabelTerreno = new javax.swing.JLabel();
        panelUnidades = new javax.swing.JPanel();
        ButtonPeon = new javax.swing.JButton();
        ButtonEscolta = new javax.swing.JButton();
        ButtonShaman = new javax.swing.JButton();
        ButtonEnfermero = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        ButtonSoldado = new javax.swing.JButton();
        ButtonTanque = new javax.swing.JButton();
        ButtonDobleAgente = new javax.swing.JButton();
        ButtonPeonElite = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        ButtonKamikaze = new javax.swing.JButton();
        ButtonFuerzasEspeciales = new javax.swing.JButton();
        ButtonPanzer = new javax.swing.JButton();
        ButtonBond007 = new javax.swing.JButton();
        ButtonNivel2 = new javax.swing.JButton();
        ButtonNivel3 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        panelEncabezado = new javax.swing.JPanel();
        panePrincipal = new javax.swing.JPanel();
        labelTitulo = new javax.swing.JLabel();
        panelLogin = new javax.swing.JPanel();
        labelJugador = new javax.swing.JLabel();
        labelRaza = new javax.swing.JLabel();
        textFNombreJugador = new javax.swing.JTextField();
        choiceRaza = new java.awt.Choice();
        botonLogin = new javax.swing.JButton();
        labelMapa = new javax.swing.JLabel();
        choiceMapa = new java.awt.Choice();
        LabelMapa = new javax.swing.JLabel();
        menuBarra = new javax.swing.JMenuBar();
        menuArchivo = new javax.swing.JMenu();
        menuPrincipal = new javax.swing.JMenuItem();
        menuServidor = new javax.swing.JCheckBoxMenuItem();
        menuCerrar = new javax.swing.JMenuItem();
        menuEditar = new javax.swing.JMenu();
        menuChat = new javax.swing.JMenu();
        menuConectados = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        panelJuego.setBackground(new java.awt.Color(0, 102, 102));
        panelJuego.setAutoscrolls(true);
        panelJuego.setPreferredSize(new java.awt.Dimension(749, 453));

        scrollPanelJuego.setBackground(new java.awt.Color(217, 83, 61));
        scrollPanelJuego.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0, 153, 102)));
        scrollPanelJuego.setForeground(new java.awt.Color(227, 20, 20));
        scrollPanelJuego.setAutoscrolls(true);

        LabelTerreno.setBackground(new java.awt.Color(255, 255, 153));
        scrollPanelJuego.setViewportView(LabelTerreno);

        panelUnidades.setBackground(new java.awt.Color(0, 153, 102));

        ButtonPeon.setText("Peon");

        ButtonEscolta.setText("Escolta");

        ButtonShaman.setText("Shaman");

        ButtonEnfermero.setText("Enfermero");

        jLabel2.setText("Unidades");

        ButtonSoldado.setText("Soldado");
        ButtonSoldado.setEnabled(false);

        ButtonTanque.setText("Tanque");
        ButtonTanque.setEnabled(false);
        ButtonTanque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonTanqueActionPerformed(evt);
            }
        });

        ButtonDobleAgente.setText("DobleAgente");
        ButtonDobleAgente.setEnabled(false);

        ButtonPeonElite.setText("PeonElite");
        ButtonPeonElite.setEnabled(false);

        ButtonKamikaze.setText("Kamikaze");
        ButtonKamikaze.setEnabled(false);

        ButtonFuerzasEspeciales.setText("FuerzasEspeciales");
        ButtonFuerzasEspeciales.setEnabled(false);

        ButtonPanzer.setText("Panzer");
        ButtonPanzer.setEnabled(false);

        ButtonBond007.setText("Bond007");
        ButtonBond007.setEnabled(false);

        ButtonNivel2.setText("2");
        ButtonNivel2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonNivel2ActionPerformed(evt);
            }
        });

        ButtonNivel3.setText("3");
        ButtonNivel3.setEnabled(false);
        ButtonNivel3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonNivel3ActionPerformed(evt);
            }
        });

        jLabel3.setText("Niveles");

        jLabel4.setText("Edificaciones");

        jButton1.setText("Mezquita");

        javax.swing.GroupLayout panelUnidadesLayout = new javax.swing.GroupLayout(panelUnidades);
        panelUnidades.setLayout(panelUnidadesLayout);
        panelUnidadesLayout.setHorizontalGroup(
            panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelUnidadesLayout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelUnidadesLayout.createSequentialGroup()
                        .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelUnidadesLayout.createSequentialGroup()
                                .addComponent(ButtonPeon)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonEscolta)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonShaman)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonEnfermero))
                            .addGroup(panelUnidadesLayout.createSequentialGroup()
                                .addComponent(ButtonSoldado)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonTanque)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonDobleAgente)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonPeonElite))
                            .addGroup(panelUnidadesLayout.createSequentialGroup()
                                .addComponent(ButtonKamikaze)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonFuerzasEspeciales)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonPanzer)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonBond007))
                            .addGroup(panelUnidadesLayout.createSequentialGroup()
                                .addGap(140, 140, 140)
                                .addComponent(jLabel2)))
                        .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelUnidadesLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonNivel3))
                            .addGroup(panelUnidadesLayout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addComponent(jLabel3))))
                    .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
                        .addComponent(jSeparator2))
                    .addComponent(ButtonNivel2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(73, 73, 73))
        );
        panelUnidadesLayout.setVerticalGroup(
            panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelUnidadesLayout.createSequentialGroup()
                .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelUnidadesLayout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelUnidadesLayout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ButtonPeon)
                            .addComponent(ButtonEscolta)
                            .addComponent(ButtonShaman)
                            .addComponent(ButtonEnfermero))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(ButtonSoldado)
                            .addComponent(ButtonTanque)
                            .addComponent(ButtonDobleAgente)
                            .addComponent(ButtonPeonElite)
                            .addComponent(ButtonNivel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelUnidadesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ButtonKamikaze)
                    .addComponent(ButtonFuerzasEspeciales)
                    .addComponent(ButtonPanzer)
                    .addComponent(ButtonBond007)
                    .addComponent(ButtonNivel3))
                .addGap(0, 19, Short.MAX_VALUE))
        );

        panelEncabezado.setBackground(new java.awt.Color(0, 153, 102));

        javax.swing.GroupLayout panelEncabezadoLayout = new javax.swing.GroupLayout(panelEncabezado);
        panelEncabezado.setLayout(panelEncabezadoLayout);
        panelEncabezadoLayout.setHorizontalGroup(
            panelEncabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 749, Short.MAX_VALUE)
        );
        panelEncabezadoLayout.setVerticalGroup(
            panelEncabezadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 38, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout panelJuegoLayout = new javax.swing.GroupLayout(panelJuego);
        panelJuego.setLayout(panelJuegoLayout);
        panelJuegoLayout.setHorizontalGroup(
            panelJuegoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelEncabezado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(scrollPanelJuego)
            .addComponent(panelUnidades, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        panelJuegoLayout.setVerticalGroup(
            panelJuegoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelJuegoLayout.createSequentialGroup()
                .addComponent(panelEncabezado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrollPanelJuego, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelUnidades, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );

        panePrincipal.setBackground(new java.awt.Color(0, 102, 102));

        labelTitulo.setFont(new java.awt.Font("Cooper Black", 0, 24)); // NOI18N
        labelTitulo.setForeground(new java.awt.Color(255, 0, 0));
        labelTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelTitulo.setText("STAR TEC");
        labelTitulo.setToolTipText("");

        panelLogin.setBackground(new java.awt.Color(0, 102, 102));

        labelJugador.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N
        labelJugador.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelJugador.setText("Nombre Jugador");

        labelRaza.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N
        labelRaza.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelRaza.setText("Raza");

        textFNombreJugador.setToolTipText("");
        textFNombreJugador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textFNombreJugadorActionPerformed(evt);
            }
        });

        botonLogin.setText("Login");
        botonLogin.setToolTipText("");
        botonLogin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonLoginActionPerformed(evt);
            }
        });

        labelMapa.setFont(new java.awt.Font("Comic Sans MS", 0, 14)); // NOI18N
        labelMapa.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        labelMapa.setText("Mapa");

        choiceMapa.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                choiceMapaItemStateChanged(evt);
            }
        });

        LabelMapa.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(131, 108, 108)));

        javax.swing.GroupLayout panelLoginLayout = new javax.swing.GroupLayout(panelLogin);
        panelLogin.setLayout(panelLoginLayout);
        panelLoginLayout.setHorizontalGroup(
            panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLoginLayout.createSequentialGroup()
                .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelLoginLayout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelRaza, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelJugador, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelMapa, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(37, 37, 37)
                        .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(choiceRaza, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textFNombreJugador, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(choiceMapa, javax.swing.GroupLayout.PREFERRED_SIZE, 229, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelLoginLayout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(botonLogin, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(92, 92, 92)))
                .addComponent(LabelMapa, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(75, 75, 75))
        );
        panelLoginLayout.setVerticalGroup(
            panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelLoginLayout.createSequentialGroup()
                .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(LabelMapa, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelLoginLayout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(labelJugador, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textFNombreJugador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelRaza, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(choiceRaza, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(labelMapa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(choiceMapa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(32, 32, 32)
                        .addComponent(botonLogin)))
                .addContainerGap(68, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panePrincipalLayout = new javax.swing.GroupLayout(panePrincipal);
        panePrincipal.setLayout(panePrincipalLayout);
        panePrincipalLayout.setHorizontalGroup(
            panePrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panePrincipalLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panePrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panePrincipalLayout.createSequentialGroup()
                        .addComponent(panelLogin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panePrincipalLayout.createSequentialGroup()
                        .addComponent(labelTitulo)
                        .addGap(333, 333, 333))))
        );
        panePrincipalLayout.setVerticalGroup(
            panePrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panePrincipalLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 39, Short.MAX_VALUE)
                .addComponent(panelLogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(25, 25, 25))
        );

        menuArchivo.setText("Archivo");

        menuPrincipal.setText("Login");
        menuPrincipal.setToolTipText("");
        menuPrincipal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuPrincipalActionPerformed(evt);
            }
        });
        menuArchivo.add(menuPrincipal);

        menuServidor.setSelected(true);
        menuServidor.setText("Servidor");
        menuArchivo.add(menuServidor);

        menuCerrar.setText("Cerrar");
        menuCerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuCerrarActionPerformed(evt);
            }
        });
        menuArchivo.add(menuCerrar);

        menuBarra.add(menuArchivo);

        menuEditar.setText("Editar");
        menuBarra.add(menuEditar);

        menuChat.setText("Chat");

        menuConectados.setText("Conectados");
        menuConectados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuConectadosActionPerformed(evt);
            }
        });
        menuChat.add(menuConectados);

        menuBarra.add(menuChat);

        setJMenuBar(menuBarra);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelJuego, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(panePrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panePrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(panelJuego, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        setSize(new java.awt.Dimension(807, 339));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void textFNombreJugadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textFNombreJugadorActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textFNombreJugadorActionPerformed

    private void menuCerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuCerrarActionPerformed
        close();
    }//GEN-LAST:event_menuCerrarActionPerformed

    private void botonLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonLoginActionPerformed
        try {
            setJuego();
            
        } catch (ParserConfigurationException | SAXException | IOException ex) {
            Logger.getLogger(STInterface.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_botonLoginActionPerformed

    private void menuPrincipalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuPrincipalActionPerformed
        menuPrincipal();
    }//GEN-LAST:event_menuPrincipalActionPerformed

    private void menuConectadosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuConectadosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_menuConectadosActionPerformed

    private void ButtonTanqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonTanqueActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ButtonTanqueActionPerformed

    private void ButtonNivel2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonNivel2ActionPerformed
        try {
            boolean subio = _jugador.subirNivel(ButtonNivel2.getText());
            
            if (subio) {
                ButtonSoldado.setEnabled(true);
                ButtonTanque.setEnabled(true);
                ButtonDobleAgente.setEnabled(true);
                ButtonPeonElite.setEnabled(true);
                
                ButtonNivel3.setEnabled(true);
                ButtonNivel2.setEnabled(false);
            }
            else {
                System.out.println("No se puede subir de nivel, minerales insuficientes!");
            }
        } 
        catch (ParserConfigurationException | SAXException | IOException ex) {
            Logger.getLogger(STInterface.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_ButtonNivel2ActionPerformed

    private void ButtonNivel3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonNivel3ActionPerformed
        try {
            boolean subio = _jugador.subirNivel(ButtonNivel3.getText());
            
            if (subio) {
                ButtonKamikaze.setEnabled(true);
                ButtonFuerzasEspeciales.setEnabled(true);
                ButtonPanzer.setEnabled(true);
                ButtonBond007.setEnabled(true);
                
                ButtonNivel3.setEnabled(false);
            }
            else {
                System.out.println("No se puede subir de nivel, minerales insuficientes!");
            }
        } 
        catch (ParserConfigurationException | SAXException | IOException ex) {
            Logger.getLogger(STInterface.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_ButtonNivel3ActionPerformed

    private void choiceMapaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_choiceMapaItemStateChanged
        try {
            setVistaPreviaTerreno();
        } catch (ParserConfigurationException | SAXException | IOException ex) {
            Logger.getLogger(STInterface.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_choiceMapaItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(STInterface.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                try {               
                    new STInterface().setVisible(true);
                } catch (ParserConfigurationException | SAXException | IOException ex) {
                    Logger.getLogger(STInterface.class.getName()).log(Level.SEVERE, null, ex);
                }
            }           
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonBond007;
    private javax.swing.JButton ButtonDobleAgente;
    private javax.swing.JButton ButtonEnfermero;
    private javax.swing.JButton ButtonEscolta;
    private javax.swing.JButton ButtonFuerzasEspeciales;
    private javax.swing.JButton ButtonKamikaze;
    private javax.swing.JButton ButtonNivel2;
    private javax.swing.JButton ButtonNivel3;
    private javax.swing.JButton ButtonPanzer;
    private javax.swing.JButton ButtonPeon;
    private javax.swing.JButton ButtonPeonElite;
    private javax.swing.JButton ButtonShaman;
    private javax.swing.JButton ButtonSoldado;
    private javax.swing.JButton ButtonTanque;
    private javax.swing.JLabel LabelMapa;
    private javax.swing.JLabel LabelTerreno;
    private javax.swing.JButton botonLogin;
    private java.awt.Choice choiceMapa;
    private java.awt.Choice choiceRaza;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel labelJugador;
    private javax.swing.JLabel labelMapa;
    private javax.swing.JLabel labelRaza;
    private javax.swing.JLabel labelTitulo;
    private javax.swing.JMenu menuArchivo;
    private javax.swing.JMenuBar menuBarra;
    private javax.swing.JMenuItem menuCerrar;
    private javax.swing.JMenu menuChat;
    private javax.swing.JMenuItem menuConectados;
    private javax.swing.JMenu menuEditar;
    private javax.swing.JMenuItem menuPrincipal;
    private javax.swing.JCheckBoxMenuItem menuServidor;
    private javax.swing.JPanel panePrincipal;
    private javax.swing.JPanel panelEncabezado;
    private javax.swing.JPanel panelJuego;
    private javax.swing.JPanel panelLogin;
    private javax.swing.JPanel panelUnidades;
    private javax.swing.JScrollPane scrollPanelJuego;
    private javax.swing.JTextField textFNombreJugador;
    // End of variables declaration//GEN-END:variables

    private void close() {
        System.exit(EXIT_ON_CLOSE);
    }
    
    private void setJuego() throws ParserConfigurationException, SAXException, 
                                   IOException {
        _usuario = textFNombreJugador.getText();
        String raza = choiceRaza.getSelectedItem();
        String mapa = choiceMapa.getSelectedItem();
        if (!_usuario.isEmpty() && !raza.equals("ELIJA SU RAZA")) {
            _jugador.set_Inicializar(raza, _usuario, mapa);
            
            servidorCliente();
            
            textFNombreJugador.setText("");
            panePrincipal.setVisible(false);
            panelJuego.setVisible(true);
            menuPrincipal.setVisible(true);
            menuServidor.setVisible(false);
            menuConectados.setVisible(true);
            setMapa ();
            this.setBounds(85, 0, 1200, 720);    
            this.setLayout(new BorderLayout());
            this.add(panelJuego, BorderLayout.CENTER);
            this.pack();
            this.setResizable(true);      
            System.out.println(_usuario + " " +raza+"-"+mapa);           
        } 
        else {
            JOptionPane.showMessageDialog(null,"Favor rellenar los campos "
                    +"\n"+"Favor Modificar.",
                    "Error",JOptionPane.ERROR_MESSAGE);
        }
    }
    
    private void setMapa () throws ParserConfigurationException, 
                                   SAXException, IOException {
        
        Image img = cargarImagenes ();
        
        ImageIcon icon = new ImageIcon(img);      
        Dimension dism = new Dimension();
        dism.setSize(icon.getIconWidth(), icon.getIconHeight());
//        dism = _jugador.setDimension(icon.getIconWidth(), icon.getIconHeight());        
        this.setPreferredSize(dism);
        LabelTerreno.setIcon(icon);        
        scrollPanelJuego.setViewportView(LabelTerreno);
        
        
    }
    
    
    private void setVistaPreviaTerreno () throws ParserConfigurationException, 
                                                SAXException, IOException {
  
        Image img = cargarImagenes ();
        Image resizedImage = img.getScaledInstance(LabelMapa.getWidth(), LabelMapa.getHeight(), 0);
        ImageIcon icon = new ImageIcon(resizedImage);        
        
        LabelMapa.setIcon(icon);
    }
    
    private Image cargarImagenes () throws ParserConfigurationException, 
                                          SAXException, IOException {
        String mapa = choiceMapa.getSelectedItem();
        String ruta = _jugador.getRutaImagenTerreno(mapa);
        
        File f = new File(ruta);
        Image img = ImageIO.read(f);
        
        return img;
    }
    
    private void menuPrincipal(){
        getNombreRazas();
        getNombreMapas();
        panePrincipal.setVisible(true);
        menuPrincipal.setVisible(false);
        menuServidor.setVisible(true);
        panelJuego.setVisible(false);
        menuConectados.setVisible(false);
        this.setLayout(new BorderLayout());
        this.add(panePrincipal, BorderLayout.CENTER);
        this.pack();
        this.setSize(700, 400);
        this.setResizable(false);
        
    }
    
    private void servidorCliente(){
        boolean Servidor = menuServidor.getState();
        if (Servidor){
            _jugador.servidor();
            _jugador.cliente();
        }
        else{
            _jugador.cliente();
        }
    }
       
    
    private void getNombreRazas(){     
        
        if (!_insertarChoiceRaza){
            _insertarChoiceRaza = true;
        
            File folder = new File("src/xml/Raza");
            File[] listOfFiles = folder.listFiles();
            choiceRaza.insert("ELIJA SU RAZA",0);
            for (int i = 0; i < listOfFiles.length; i++) {      
                choiceRaza.insert(listOfFiles[i].getName(), i+1);
            }
        }
    }
    
    private void getNombreMapas() {
        File folder = new File("src/xml/Mapa");
        File[] listOfFiles = folder.listFiles();
        for (int i = 0; i < listOfFiles.length; i++) {
            choiceMapa.insert(listOfFiles[i].getName(), i+1);
        }
    }
 }